/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package semmatch;


import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Aliz
 */

public class Concept implements Comparable{
    
    LinkedList parents[];
    String id;
    int mindepth;
    int maxdepth;
    public Concept(String id,int depth)
    {
        parents=new LinkedList[Constants.MAX_DEPTH];
        for (int i=0;i<Constants.MAX_DEPTH;i++)
            parents[i]=new LinkedList<Concept>();
        this.id=id;
        this.mindepth=depth;
        this.maxdepth=depth;
    }
    public void addParent(int depth, Concept parentC)
    {
       if (!parents[depth].contains(parentC))
            parents[depth].add(parentC);
        if (maxdepth<depth) maxdepth=depth+1;
    }
      public void addAncestors(int depth, List<Concept> parentC)
    {
       if (!parentC.isEmpty()){
           for (Concept c:parentC)
               if (!isAncestor(depth,c))
                    parents[depth].add(c);
        }
    }

    public int getMaxdepth() {
        return maxdepth;
    }

    public void setMaxdepth(int maxdepth) {
        this.maxdepth = maxdepth;
    }

    public int getMindepth() {
        return mindepth;
    }

    public void setMindepth(int mindepth) {
        this.mindepth = mindepth;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    boolean isAncestor(int j, Concept c) {
        for (int i=0;i<=j;i++)
        {
            if (parents[i].contains(c))
                return true;
        }
        return false;
    }
    int ancestorDepth(Concept c) {
        for (int i=0;i<Constants.MAX_DEPTH;i++)
        {
            if (parents[i].contains(c))
                return i;
        }
        return -1;
    }
   public double appartenance(Concept c)
    {
        int k=ancestorDepth(c);
        double d=1;
        for (int i=0;i<=k;i++)
            d*=Constants.APPART;
        return d;
   }

    public int compareTo(Object o) {
       if (! (o instanceof Concept)) return -1;
       return this.id.compareTo(((Concept)o).getId());

    }
    
}
